#ifndef WALL_H
#define WALL_H

#include <QLinkedList>
#include <QPoint>
#include <cstdlib>

class Wall : public QLinkedList<QPoint>
{
public:
    //based on bresenhams algorithm

    static Wall buildWall(QPoint p0, QPoint p1)
    {
      //  qDebug() << "bresenhamsLine:enter";
      //  qDebug() << p0 << "@" << p1;
        Wall ret;
        bool steep =
                (std::abs(p0.y() - p1.y()) >
                 std::abs(p0.x() - p1.x()));

       // qDebug() << "steep:" << steep;

        if(steep)
        {
            int tmp = p0.x();
            p0.setX(p0.y());
            p0.setY(tmp);

            tmp = p1.x();
            p1.setX(p1.y());
            p1.setY(tmp);
        }

        if(p0.x() > p1.x())
        {
            qSwap(p0,p1);
        }
        int deltaX = p1.x() - p0.x();
        int deltaY = std::abs(p1.y() - p0.y());
        double error = 0;
        Q_ASSERT(deltaX > 0);
        double deltaErr = (double)deltaY / (double)deltaX;
        int ystep;
        int y = p0.y();
        if(p0.y() < p1.y())
            ystep = 1;
        else
            ystep = -1;

        for(int x=p0.x() ; x != p1.x() ; x++)
        {
            //qDebug() << "x:" << x;
            if(steep)
            {
                QPoint newPoint(y,x);
                ret << newPoint;
                //_plane[y][x].setWall(true);

            }
            else
            {
                QPoint newPoint(x,y);
                ret << newPoint;
                //_plane[x][y].setWall(true);
            }
            error+=deltaErr;
            if(error >= 0.5)
            {
                y+=ystep;
                error-=1.0;
            }
        }
       // qDebug() << "bresenhamsLine:leave";

        return ret;

    }


private:
     Wall();
};

#endif // WALL_H
